package com.stone.framework.user.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.stone.framework.message.user.RoleUserPageReqBody;
import com.stone.framework.message.user.RoleUserPageResBody;
import com.stone.framework.user.entity.RoleUser;

@Mapper
public interface RoleUserMapper extends BaseMapper<RoleUser> {

    @Select("SELECT sru.id, sru.role_id, sru.user_id, su.name as username, su.cname, su.dept_code, sd.name as dept_name FROM ST_ROLE_USER sru JOIN ST_USER su ON sru.user_id = su.id AND su.state = 'ENABLED' LEFT JOIN ST_DEPT sd ON su.dept_code = sd.code ${ew.customSqlSegment}")
    IPage<RoleUserPageResBody> selectPage(Page<RoleUserPageResBody> page,
        @Param(Constants.WRAPPER) Wrapper<RoleUserPageReqBody> queryWrapper);

}
